import kotlinx.coroutines.internal.synchronized
import java.util.logging.Logger

class SimpleCache(override var size: Long=0L) :Cache {
    private val map = hashMapOf<String, Any>()
    private val logger: Logger = Logger.getLogger(SimpleCache::javaClass.name)

    init {
        logger.info("initialize simple cache")
    }

    @Synchronized
    override fun set(key: String, value: Any) {
            map[key] = value
            addOne()
    }

    override fun get(key: String): Any? {
        val value = map[key]
        return value
    }

    override fun remove(key: String):Any? {
        minusOne()
        return map.remove(key)
    }

    override fun clear() {
        map.clear()
    }

}